#ifndef DBMYSQL_H
#define DBMYSQL_H


#include <iostream>
#include <map>

#include "ado/stdafx.h"
#include "standard/DBConfig.h"

#if defined(__GNUC__)
#include <mysql/mysql.h>
#endif

#if defined(_MSC_VER)

#include<WinSock2.h>
#include<mysql.h>
#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib,"libmysql.lib")

#define IF_TEST_DBMYSQL 0
#endif




class   ADOLIB1_API DbMysql
{
public:
    static DbMysql* instance();
    //MYSQL* connect(std::string module_name);
    //MYSQL* connect(void *tData);
    MYSQL* connect(const char *dbname);
    std::string get_dbprefix();
    std::string get_defaultdb();
    std::string get_dbname();
    int MysqlPing(MYSQL* conn);
    DbMysql* execute(const char*);
    MYSQL_RES* getResult();
    int insert_id();
    std::map<std::string, std::string> getRow();
    std::map<unsigned long int, std::map<std::string, std::string> > getArray();
    int getNumField();
    std::map<unsigned long int, std::string> getArrayField();
    unsigned long int getNumRow();
    void close();
    void close(MYSQL* _mysql);   
	DbMysql();
private:
    MYSQL           mysql;
    MYSQL_RES*      _results;  
    DBConfig     m_Config;
    //void*           m_ConfigMap;
    std::string     m_dbhost;
    std::string     m_dbuser;
    std::string     m_dbpass;
    std::string     m_dbname;
    std::string     m_dbprefix;
    std::string     m_dbcharset;  

    static DbMysql* _instance;
    class CGarbo {public: ~CGarbo(){if (DbMysql::_instance) delete DbMysql::_instance;}};
    static CGarbo Garbo;
};



#endif
